/* let str = 'string to search';
let index = str.search(/to/);
console.log(index); */

/* let str = 'aaa bbb;ccc:ddd#eee';
let result = str.split(/((\s|;|:|#)+)/);
console.log(result); */

/* function trim(str){
    return str.replace(/^\s+|\s$/g,'');
}
let str = '  hello  ';
//let result = str.trim();
let result = trim(str);
console.log(result);
 */

//老师  function(matched  index )在讲讲吧  是针对哪个函数

const str = 'create-react-app';
String.prototype.replace = function(regexp,fn){
   let result;
   do{
    ///-([a-zA-Z])/g.exec('create-react-app');
    result = regexp.exec(this);//[matched,group1,group2...,index,input]
    let replaced = fn(...result,result.index,result.input);//R
    //把原来的-r变成R
   }while(result);
}
str.replace(/-([a-zA-Z])/g,function(matched,group1,index,input){
    //matched=-r
    //group1=r=R
    //index=6
    //input=create-react-app
    return group1.toUpperCase();
});